package kessai;

import shouhin.ShouhinBeans;
import kaiin.KaiinBeans;
import java.net.URI;
import java.net.URISyntaxException;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BuyCheck extends HttpServlet{

	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws IOException, ServletException{
		this.doPost(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws IOException, ServletException{

		req.setCharacterEncoding("utf-8");

		HttpSession session = req.getSession(true);
		KaiinBeans kaiin = (KaiinBeans)session.getAttribute("kaiin");

		if(kaiin == null || !kaiin.isLogIn()){

			kaiin = new KaiinBeans();
			kaiin.setSimei(req.getParameter("name"));
			kaiin.setHurigana(req.getParameter("ruby"));
			kaiin.setYuubin1(req.getParameter("postcode1"));
			kaiin.setYuubin2(req.getParameter("postcode2"));
			kaiin.setJuusyo(req.getParameter("address1"));
			kaiin.setTel(req.getParameter("tel"));
			session.setAttribute("kaiin", kaiin);
		}

		String flag = req.getParameter("flag");

		//テスト用カート作成上書き
//		CartBeans cbean = new CartBeans();
//		ShouhinBeans item = new ShouhinBeans();
//
//		item.setSyouhin_id(9999);
//		item.setSyouhinmei("テスト");
//		item.setNedan(9999);
//		item.setKosuu(9999);
//
//		cbean.addItem(item);
//		session.setAttribute("cart", cbean);

		//テスト用ここまで

		RequestDispatcher dp = req.getRequestDispatcher("../src/jsp/kessai/cart_conf.jsp");

		dp.forward(req, res);
	}
}
